package com.link.base.wechat.wxsubscriber.controller;

import com.link.base.wechat.wxsubscriber.model.Subscriber;
import com.link.base.wechat.wxsubscriber.service.WxSubscriberService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 为微服务增加controller层
 * @author 刘永枭
 */
@Controller
@RequestMapping("/link/wxsubscriber")
public class WxSubscriberController extends BasicController<Subscriber> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private WxSubscriberService wxSubscriberService;

    @Override
    public BasicService<Subscriber> getBasicService() throws Exception {
        return wxSubscriberService;
    }

    /**
     * 更新微信粉丝
     * @param entity
     * @return
     */
    @RequestMapping(value = "/updateSub", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateSub(@RequestBody Subscriber entity) {
        Map<String, Object> result = new HashMap<>(3);
        try {
            wxSubscriberService.updateSub(entity);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
